package easy._108_ConvertSortedArraytoBinarySearchTree;

public class ConvertSortedArraytoBinarySearchTree {
    public TreeNode sortedArrayToBST(int[] nums) {
        int height = nums.length;
        if(height==0) return null;
        return getSubTree(nums,0,height-1);
    }

    public TreeNode getSubTree(int[] nums,int low,int high){
        if(low>high) return null;
        int mid = (low+high)/2;
        TreeNode node = new TreeNode(nums[mid]);
        node.left = getSubTree(nums,low,mid-1);
        node.right = getSubTree(nums,mid+1,high);
        return node;
    }
}
